package gov.pr.celepar.sentinela.util;

public class SentinelaUtil {

	public static String getHoraFromMinutos(int i) {
		String str = "";
		int ptInt, ptQueb;
		ptInt = i / 60;
		ptQueb = i - (ptInt * 60);
		if (ptInt + ptQueb >= 0)
			str = "" + (ptInt < 10 ? "0" + ptInt : "" + ptInt) + ":"
					+ (ptQueb < 10 ? "0" + ptQueb : "" + ptQueb);
		return str;
	}

	public static int getMinutosFromHora(String str) {
		if (str == null)
			return -1;
		int iPtInt = 0, iPtQueb = 0;
		try {
			int iIndice = str.indexOf(':');
			String pt1 = str.substring(0, iIndice);
			String pt2 = str.substring(iIndice + 1, str.length());
			iPtInt = Integer.parseInt(pt1);
			iPtQueb = Integer.parseInt(pt2);
		} catch (Exception e) {
			return 0;
		}
		return (iPtInt * 60) + iPtQueb;
	}

	public static synchronized String retiraParametrosURL(String str) {
		String res = null;
		if (str == null)
			return null;
		int i = str.indexOf('?');
		if (i < 0)
			res = str;
		else {
			res = str.substring(0, i);
		}
		return res;
	}

	public static String addCharBefore(String param, char caractere, int tamanho) {
		StringBuilder sb = new StringBuilder(tamanho);
		sb.append(param != null ? param : "");

		while (sb.length() < tamanho)
			sb.insert(0, caractere);

		return sb.toString();
	}
}